package com.yang.job.client.dto.common;


import java.io.Serializable;

public class Response<T> implements Serializable {
    private Integer code;

    private String msg;

    private T data;

    private Response(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Response(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public static Response fail() {
        return Response.fail(ErrorCode.FAIL);
    }

    public static Response fail(String msg) {
        return new Response(ErrorCode.FAIL.getCode(), msg);
    }

    public static Response fail(ErrorCode errorCode) {
        return new Response(errorCode.getCode(), errorCode.getMsg());
    }

    public static <T> Response<T> success() {
        return new Response<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg());
    }

    public static <T> Response<T>  success(T data) {
        return new Response<>(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), data);
    }
}

